﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace serie03_malprogramm
{
    public partial class Form1 : Form
    {
        bool paint = false;
        SolidBrush color;
        SolidBrush backgroundColor;
        SolidBrush brushColor;
        Bitmap offScreen;
        Graphics bitmapGraphics;
        Graphics xGraphics;

        public Form1()
        {
            InitializeComponent();
            brushColor = new SolidBrush(Color.Black);
            backgroundColor = new SolidBrush(panel1.BackColor);
            color = brushColor;
            //offScreen = new Bitmap(panel1.Width, panel1.Height);
            //bitmapGraphics = Graphics.FromImage(offScreen);
            //bitmapGraphics.Clear(Color.White);
            //xGraphics = panel1.CreateGraphics();

        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            //e.Graphics.DrawImage(offScreen, 0, 0);
        }

        private void btnExitClick(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnClearClick(object sender, EventArgs e)
        {
            Graphics g1 = panel1.CreateGraphics();
            g1.Clear(panel1.BackColor);
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            paint = false;
            //bitmapGraphics = Graphics.FromImage(offScreen);
            //bitmapGraphics.Clear(Color.White);
            //offScreen = new Bitmap(panel1.Width, panel1.Height); 
            //xGraphics.DrawImage(offScreen, 0, 0);
            //bitmapGraphics.DrawImage(offScreen, 0, 0);
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            paint = true;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (paint)
            {
                Graphics g = panel1.CreateGraphics();
                g.FillEllipse(color, e.X, e.Y, 10, 10);

                //Graphics g = Graphics.FromImage(offScreen);
                //xGraphics.DrawImage(offScreen, 0, 0);
                //xGraphics.FillEllipse(color, e.X, e.Y, 10, 10);
                ////g.Dispose();
                ////g.DrawImage(offScreen, 0, 0);
                //Invalidate();
            }
        }

        private void btnUndoClick(object sender, EventArgs e)
        {

        }

        private void btnRechteckClick(object sender, EventArgs e)
        {

        }

        private void btnEllipseClick(object sender, EventArgs e)
        {

        }

        private void btnLinieClick(object sender, EventArgs e)
        {

        }

        private void btnRadiererClick(object sender, EventArgs e)
        {
            color = backgroundColor;
        }

        private void btnStiftClick(object sender, EventArgs e)
        {
            color = brushColor;
        }

        private void btnColorSelectClick(object sender, EventArgs e)
        {
            colorDialog1.FullOpen = true;
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                Color customColor = colorDialog1.Color;
                this.color = new SolidBrush(customColor);
            }
        }


    }
}
